﻿var columns =
            [
                 { display: 'Key', name: 'Id', type: 'text', hide: 1 },
                { display: '仓库名', name: 'StorehouseName', mintWidth: 80, width: 120 }, 
                {display: '仓库编码', name: 'StorehouseCode', mintWidth: 80, width: 120 },
                { display: '状态', name: 'DeletedSate', mintWidth: 60, width: 80 },
                {display: '仓库类别', name: 'StorehouseTypeName', mintWidth: 80, width: 140 },
                { display: '组织机构名称', name: 'OrgName', mintWidth: 80, width: 140 },
                 { display: '备注', name: 'Remarks', mintWidth: 140, width: 200 }
             ];

var manager;
//init controls
$(document).ready(function () {
    initligerGrid();
});

function initligerGrid() {
    manager = null;
    manager = $("#WareHoseGrid").ligerGrid({
        columns: columns,
        title: '仓库列表',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
                                    { text: '增加', click: dialogAdd, icon: 'add' },
                                    { line: true },
                                    { text: '修改', click: modifyOperation, icon: 'modify' },
                                    { line: true },
                                    { text: '删除', click: deleteOperation, img: '../Content/images/delete.gif' }
                                    ]
        },
        url: "../WareHose/GetWareHoses?rand="+Math.random()
    });
}
//add
function dialogAdd() {
    $.ligerDialog.open({ url: '../WareHose/Add', height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false});
}

//delete
function deleteOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
        if (yes) {
            $.get("../WareHose/Delete?wareHourseId=" + row["Id"].toString(), {}, function (data) {
                if (data != undefined && data == "9") {
                    initligerGrid();
                }
            });
        }
    });
}
//update 
function modifyOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    $.ligerDialog.open({ url: '../WareHose/Edit?wareHourseId=' + row["Id"].toString(), height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
}


